﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Hr.IBLL;
using Hr.IDAL;
using Hr.DALContainer;
using Hr.Model;
using System.Data.Entity;
using Hr.DAL;

namespace Hr.BLL
{
    public partial class ProcessService : BaseService<Process_List>, IProcess_ListService
    {
        // 实现接口
        private IProcess_ListDAL Process_ListService = Container.Resolve<IProcess_ListDAL>();
        //创建EF对象
        private DbContext db = DbContextFactory.Create();

        //引入DAL层
        protected ProcessDAL Rdl = new ProcessDAL();

        //BLL层核心代码
        #region 获取流程管理页面信息(自己申请的流程)
        /// <summary>
        /// 获取流程管理页面信息(自己申请的流程)
        /// </summary>
        /// <param name="id"></param>
        /// <returns>流程管理</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/15</create>
        /// <updata>null</updata>

        public Dictionary<string, object> SendProcessList(int page, int limit, int fk_User)
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"ProcessList",Rdl.SendProcessList(fk_User).Skip(limit*(page-1)).Take(limit) },
                {"Count",Rdl.SendProcessList(fk_User).Count() }
            };
            return dt;
        }
        #endregion

        #region 流程管理添加下拉框绑定
        /// <summary>
        /// 流程管理添加下拉框绑定
        /// </summary>
        /// <param name="id"></param>
        /// <returns>流程管理</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/17</create>
        /// <updata>null</updata>

        public IEnumerable<Sys_TypeID> SelectTypeBinding()
        {
            return Rdl.SelectTypeBinding();
        }
        #endregion

        #region 流程管理添加
        /// <summary>
        /// 流程管理添加
        /// </summary>
        /// <param name="id"></param>
        /// <returns>流程管理</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/17</create>
        /// <updata>null</updata>

        public bool AddProcessList(Process_List PList, int fk_User)
        {
            Rdl.AddProcessList(PList, fk_User);
            return Rdl.Savechanges();
        }
        #endregion

        #region 根据Title获取流程管理页面信息(自己申请的流程)
        /// <summary>
        /// 根据Title获取流程管理页面信息(自己申请的流程)
        /// </summary>
        /// <param name="id"></param>
        /// <returns>流程管理</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/15</create>
        /// <updata>null</updata>
        public Dictionary<string, object> TitleSelectProcessList(int page, int limit, int fk_User, string Title)
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"ProcessList",Rdl.TitleSelectProcessList(fk_User,Title).Skip(limit*(page-1)).Take(limit) },
                {"Count",Rdl.TitleSelectProcessList(fk_User,Title).Count() }
            };
            return dt;
        }
        #endregion

        #region 流程审核页面(获取需要自己审核的流程)
        /// <summary>
        /// 流程审核页面(获取需要自己审核的流程)
        /// </summary>
        /// <param name="id"></param>
        /// <returns>流程审核</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/15</create>
        /// <updata>null</updata>

        public Dictionary<string, object> SendAuditProcessList(int page, int limit, int fk_User)
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"ProcessList",Rdl.SendAuditProcessList(fk_User).Skip(limit*(page-1)).Take(limit) },
                {"Count",Rdl.SendAuditProcessList(fk_User).Count() }
            };
            return dt;
        }
        #endregion

        #region 根据Title获取流程审核页面(获取需要自己审核的流程)
        /// <summary>
        /// 根据Title获取流程审核页面(获取需要自己审核的流程)
        /// </summary>
        /// <param name="id"></param>
        /// <returns>流程审核</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/15</create>
        /// <updata>null</updata>

        public Dictionary<string, object> TitleSelectAuditProcessList(int page, int limit, int fk_User, string Title)
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"ProcessList",Rdl.TitleSelectAuditProcessList(fk_User,Title).Skip(limit*(page-1)).Take(limit) },
                {"Count",Rdl.TitleSelectAuditProcessList(fk_User,Title).Count() }
            };
            return dt;
        }
        #endregion

        #region 获取流程汇总页面(全部流程)
        /// <summary>
        /// 获取流程汇总页面(全部流程)
        /// </summary>
        /// <param name="id"></param>
        /// <returns>流程汇总</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/15</create>
        /// <updata>null</updata>

        public Dictionary<string, object> SummaryProcessList(int page, int limit, int fk_User)
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"ProcessList",Rdl.SummaryProcessList(fk_User).Skip(limit*(page-1)).Take(limit) },
                {"Count",Rdl.SummaryProcessList(fk_User).Count() }
            };
            return dt;
        }
        #endregion

        #region 根据Title获取流程汇总页面
        /// <summary>
        /// 根据Title获取流程汇总页面
        /// </summary>
        /// <param name="id"></param>
        /// <returns>流程汇总</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/15</create>
        /// <updata>null</updata>

        public Dictionary<string, object> TitleSelectSummaryProcessList(int page, int limit, int fk_User, string Title)
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"ProcessList",Rdl.TitleSelectSummaryProcessList(fk_User,Title).Skip(limit*(page-1)).Take(limit) },
                {"Count",Rdl.TitleSelectSummaryProcessList(fk_User,Title).Count() }
            };
            return dt;
        }
        #endregion

        #region 流程汇总页面删除功能
        /// <summary>
        /// 流程汇总页面删除功能
        /// </summary>
        /// <param name="id">pk_Process</param>
        /// <returns>流程汇总删除</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/15</create>
        /// <updata>null</updata>

        public bool DelSummaryProcessList(int pk_Process)
        {
            Rdl.DelSummaryProcessList(pk_Process);
            return Rdl.Savechanges();
        }
        #endregion

        #region 查看页面根据pk_Process查询
        /// <summary>
        /// 查看页面根据pk_Process查询
        /// </summary>
        /// <param name="id">pk_Process</param>
        /// <returns>查看页面</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/17</create>
        /// <updata>null</updata>

        public object ProcessDataBinding(int pk_Process)
        {
            return Rdl.ProcessDataBinding(pk_Process);
        }
        public IEnumerable<object> ProcessViewBinding(int pk_Porcess)
        {
            //item.GetType().GetProperty("FullName").GetValue(item).ToString();
            return Rdl.ProcessViewBinding(pk_Porcess);
        }
        #endregion

        #region 流程审核 同意和驳回
        /// <summary>
        /// 流程审核
        /// </summary>
        /// <param name="id">pk_Process</param>
        /// <returns>流程审核</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/18</create>
        /// <updata>null</updata>

        //同意
        public bool ProcessAgree(int pk_Process, int CheckUser, int StatusID, string Note)
        {
            Rdl.ProcessAgree(pk_Process, CheckUser, StatusID, Note);
            return Rdl.Savechanges();
        }
        //驳回
        public bool ProcessRejected(int pk_Process, int CheckUser, int StatusID, string Note)
        {
            Rdl.ProcessAgree(pk_Process, CheckUser, StatusID, Note);
            return Rdl.Savechanges();
        }
        #endregion

        #region 是否禁用按钮
        /// <summary>
        /// 是否禁用按钮
        /// </summary>
        /// <param name="id">pk_Process,CheckUser</param>
        /// <returns>流程审核</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/18</create>
        /// <updata>null</updata>

        public int IsButton(int pk_Process, int CheckUser)
        {
            return Rdl.IsButton(pk_Process, CheckUser);
        }

        #endregion

        public override void SetDal()
        {
            Dal = Process_ListService;
        }
    }
}
